<?php namespace App\Http\Services;

use App\User;
use App\Http\Services\Tools;
use Carbon\Carbon;

class UserManager
{
    /**
     * 检查手机号码是否已经存在或已经被使用
     * @param $phone
     * @return bool
     */
    public static function isPhoneExists($phone){
        if(User::wherePhone($phone)->exists())
            return true;
        return false;
    }

    /**
     * 用户注册对应方法
     * @param $username
     * @param $email
     * @param $phone
     * @param $password
     * @return User
     */
    public static function signUp($phone, $password){
        $user              = new User();
        $user->phone       = Tools::isPhone($phone) ? $phone:null;
        $user->password    = bcrypt($password);
        $user->reg_time    = Carbon::now();
        $user->login_ip    = NULL;
        $user->login_time  = date('Y-m-d',time());
        $user->login_count = 1;
        $user->status      = 1;
        $user->save();

        return $user;
    }
}